package com.liuyucheng.idea_springboot.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserService implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher eventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher;
    }

    public void registerUser(String username) {
        // 用户注册逻辑
        log.info("用户 {} 注册成功！", username);

        // 发布用户注册事件
        eventPublisher.publishEvent(new UserRegisteredEvent(this, username));
    }
}